define(function(require, exports){
	var $      = require("jquery");
	var util   = require('util');
	var pubjs  = require('pubjs');
	var popwin = require('@base/dialog').base;

	// 导入导出窗口
	var Base = popwin.extend({
		init: function(config, parent){
			config = pubjs.conf(config, {
				'title': LANG('导出窗口'),
				'width': 700,
				'textRow': 15,
				'noProcess': false
			});

			this.$text  = null;
			this.Super('init', arguments);
		},
		afterBuild: function(){
			this.Super('afterBuild', arguments);
			var c = this.getConfig();
			var container = this.getContainer();

			this.$text = $('<textarea style="width:100%; height:auto; padding:0;"/>').appendTo(container).addClass('form-element mb10 mt10');
			if (c.textRow){
				this.$text.attr('rows', c.textRow);
			}

			var btnWrap = $('<div class="tc mt15"></div>').appendTo(container);
			var copyBtn = $('<input type="button" class="btn btn-default copy"/>').val(LANG('复制')).appendTo(btnWrap);

			// this.uiBind(copyBtn, 'click', 'eventCopy');
			pubjs.customClipboard(this.$text, copyBtn, this.copyComplete);
			this.update();
		},
		setData: function(text){
			this.$text.val(text);
			return this;
		},
		getData: function(){
			return this.$text.val();
		},
		onOk: function(ev){
			var data = this.getData();
			var c = this.getConfig();

			this.hide();

			if (c.noProcess){
				this.fire('importList', data);
				return false;
			}
			var lines = data.split('\n');
			var list  = [];
			var datas = [];
			util.each(lines, function(line){
				var id = util.trim(line.split('\t').shift());
				if (id && !isNaN(+id)){
					list.push(id);
					datas.push(line);
				}
			});

			this.fire(
				"importList"
				,{
					"list":list
					,"lines":datas
				}
			);
			return false;
		},
		copyComplete: function(evt, elm){
			pubjs.alert(LANG('复制成功'));
		}
	});

	exports.base = Base;

});